package com.wms.ymcc.service.impl;

import com.wms.ymcc.constant.ValidationConstants;
import com.wms.ymcc.service.ITokenService;
import com.wms.ymcc.util.StrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author : 阿盛哟
 * @description : token服务实现类
 * @createDate : 2025/6/21 20:42
 */
@Service
public class TokenServiceImpl implements ITokenService {

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;


    @Override
    public String createToken(Long id) {
        /**
         * 1. 生成一个token
         * 2. 存入redis，给一个过期时间
         * 3. 返回token给页面
         */
        String token = StrUtils.getComplexRandomString(16);
        redisTemplate.opsForValue().set(
                ValidationConstants.REDIS_KEY_TOKEN_KEN,
                token,
                10,
                TimeUnit.MINUTES
        );

        return token;
    }
}